import * as mongoose from 'mongoose';

export const CorpAppSchema = new mongoose.Schema({
  appId: { type: String, unique: true, index: true },
  corpId: { type: String, index: true },
  name: String,
  description: String,
  logo: String,
  homepage: String,
  appType: { type: Number, default: 1 }, // 1-应用 2-小程序
  config: { type: mongoose.Schema.Types.Mixed, required: false },
  permissions: { type: mongoose.Schema.Types.Mixed, required: false },
  secret: String,
  token: String,
  aesKey: String,
  status: { type: Number, default: 1 }, // 1-正常 2-禁用
  wxAppInfo: { type: mongoose.Schema.Types.Mixed, required: false },
  teamId: Number,
  create_time: { type: Number, default: () => Date.now() },
  update_time: { type: Number, default: () => Date.now() },
}, {
  collection: 'corp_apps',
  timestamps: { currentTime: () => Date.now() }
});

// 添加索引
CorpAppSchema.index({ appId: 1 }, { unique: true });
CorpAppSchema.index({ corpId: 1 });
CorpAppSchema.index({ status: 1 });
CorpAppSchema.index({ create_time: -1 });